# 2024.06.25——CSDN博客——【Python】专栏
# 数据类型——2024.06.26完成

# 数据类型
a = 1   # 数字（Number)
b = 'A'     # 字符串（String）
c = True    # 布尔（bool）
tup = (a, b, c)    # 元组（Tuple）
# tup[0] = b
# tup[1] = a
# tup[2] = False

# 值可变的数据类型
lis = [a, b, c]     # 列表（List）
dic = {a: 1, b: 'A', c: True}   # 字典（Dictionary)
Set = {a, b, c}     # 集合（Set）
print(f"修改前：lis = {lis}")
lis[0] = b
lis[1] = a
lis[2] = False
print(f"修改后：lis = {lis}\n")

# 动态数据类型
trend = 2 ** 31 - 1  # 此时的数据类型是整型，值为整型最大值
print(trend)
print(f"type(trend) = {type(trend)}\n")
trend += 1  # 此时的数据类型是整型，值为整型最大值+1
print(trend)
print(f"type(trend) = {type(trend)}\n")
trend = 'string'
print(trend)
print(f"type(trend) = {type(trend)}\n")
trend = 3.1415926
print(trend)
print(f"type(trend) = {type(trend)}\n")

# 字符串类型
a = 1   # Number——整型
print(type(a))
b = 1.2     # Number——浮点型
print(type(b))
print(f"{a} + {b} = {a + b}\n")
d = True    # bool——布尔型（int型的分支）
print(type(d))
print(f"{a} + {d} = {a + d}\n")

# c = 'string'    # String——字符串型
# print(type(c))
# print(f"{a} + {c} = {a + c}\n")
# e = (1, 2, 3)   # tuple——元组型
# print(type(e))
# print(f"{a} + {e} = {a + e}\n")
# f = [1, 2, 3]   # list——列表型
# print(type(f))
# print(f"{a} + {f} = {a + f}\n")
# g = {1: 1, 2: 2, 3: 3}  # Dictionary——字典型
# print(type(g))
# print(f"{a} + {g} = {a + g}\n")
# h = {1, 2, 3}   # Set——集合型
# print(type(h))
# print(f"{a} + {h} = {a + h}\n")

# 布尔类型
a = True
b = False
if a:
    print('hello ', end='')
else:
    print('hi', end='')
if b:
    print('你好\n')
else:
    print('world\n')
print(f"{a} + {1} = {a + 1}\n")
print(f"{b} + {1} = {b + 1}\n")

# 隐式转换
a = 1
b = 1.1
c = a + b
d = True
e = a + d
f = complex(1, 2)
g = b + f
print(f"type(a) = {type(a)}")
print(f"type(b) = {type(b)}")
print(f"type(c) = {type(c)}")
print(f"type(d) = {type(d)}")
print(f"type(e) = {type(e)}")
print(f"type(f) = {type(f)}")
print(f"type(g) = {type(g)}\n")

# int(x[, base=10])
a = '10'
b = int(a)
print(f"a = {a}\tb = {b}\n")
print(f"type(a) = {type(a)}\ttype(b) = {type(b)}\n")
c = int(a, 2)
print(f"a = {a}\tc = {c}\n")
print(f"type(a) = {type(a)}\ttype(c) = {type(c)}\n")

# int(x, base=16)
a = '123456789abcdef'
b = int(a, 16)
print(f"a = {a}\tb = {b}\n")
print(f"type(a) = {type(a)}\ttype(b) = {type(b)}\n")

# a = '123456789abcdefg'
# b = int(a, 16)
# print(f"a = {a}\tb = {b}\n")
# print(f"type(a) = {type(a)}\ttype(b) = {type(b)}\n")

# a = 16
# b = int(a, 16)
# print(f"a = {a}\tb = {b}\n")
# print(f"type(a) = {type(a)}\ttype(b) = {type(b)}\n")

a = 1.9
b = int(a)
print(f"a = {a}\tb = {b}\n")
print(f"type(a) = {type(a)}\ttype(b) = {type(b)}\n")
